import storageApi from '../../core/storage/storage';
import BaseController from '../../core/controllers/Base.controller';

@Inject('$log', '$rootScope', '$state', 'globalService', 'personalWorkbenchService', 'ngDialog', 'ngDialogService')
class DeviceInfoController extends BaseController {
  constructor() {
    super();

    const type = $state.params.type;
    this.type = type;
    if (type === '1') {
      this.workbenchStatus = '待办';
    } else if (type === '2') {
      this.workbenchStatus = '进行中';
    } else if (type === '3') {
      this.workbenchStatus = '已完成';
    }

    this.paginationService = this.personalWorkbenchService;
    this.$setQueryCallback((res) => {
      this.equipListData = res.rows;
    });

    this.mapParams = {
      orgId: $rootScope.orgId || storageApi.get('orgId'),
      // deviceName: '',
      // code: '',
      // inOutStatus: '',
      // sortType: 1,
    };
    this.mapParams.inOutStatus = '';
    this.$paginationQuery();
    // 全选
    this.toggleAllFlag = false;
  }

  $query(param) {
    if (param && param.inTimeMin.$valid && param.inTimeMax.$valid
      && param.inTimeMin.$viewValue > param.inTimeMax.$viewValue) {
      this.ngDialogService.alertError('进场时间开始时间应小于结束时间');
      return;
    }
    this.$paginationQuery();
  }

  $reset() {
    this.mapParams = {
      orgId: this.$rootScope.orgId || storageApi.get('orgId'),
    };
  }
}

export default DeviceInfoController;
